package WarTug;

import org.newdawn.slick.opengl.Texture;

//Buttons are the only thing that will EVER HAVE TEXT

public class Button implements Drawable {
	public static final double z = 10.0;
	
	protected double x,y,w,h;
	protected Texture texture;
	protected String text; 
	protected ButtonAction act;
	
	
	public Button(double x, double y, double width, double height){
		this(x,y,width,height,null,null,null);
	}
	
	public Button(double x, double y, double width, double height, String text){
		this(x,y,width,height,text,null,null);
	}
	
	public Button(double x, double y, double width, double height, String text, Texture texture){
		this(x,y,width,height,text,texture,null);
	}
	
	public Button(double x, double y, double width, double height, Texture texture){
		this(x,y,width,height,null,texture,null);
	}
	
	public Button(double x, double y, double width, double height, Texture texture, ButtonAction action){
		this(x,y,width,height,null,texture,action);
	}
	
	public Button(double x, double y, double width, double height, String text, Texture texture, ButtonAction action){
		this.setX(x);
		this.setY(y);
		setWidth(width);
		setHeight(height);
		setText(text);
		setTexture(texture);
		setAction(action);
	}

	public void setX(double x) {
		this.x = x;
	}

	public double getX() {
		return x;
	}

	public void setY(double y) {
		this.y = y;
	}

	public double getY() {
		return y;
	}
	
	public double getZ() {
		return z;
	}

	public void setWidth(double w) {
		this.w = w;
	}

	public double getWidth() {
		return w;
	}

	public void setHeight(double h) {
		this.h = h;
	}

	public double getHeight() {
		return h;
	}

	public void setTexture(Texture texture) {
		this.texture = texture;
	}

	public Texture getTexture() {
		return texture;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getText() {
		return text;
	}

	public void setAction(ButtonAction act) {
		if (act == null){
			this.act = new ButtonAction() {
				public void onClick() {}
				public void hover() {}};
		} else
			this.act = act;
	}

	public ButtonAction getAction() {
		return act;
	}
	
	private boolean inLine(double p, double start, double len){
		return p>=start && p<=(start+len);
	}
	
	public boolean takeClick(double x, double y){
		if(inLine(x,this.x -(w/2),w) && inLine(y,this.y-(h/2),h)){ //yes clicked
			act.onClick();
			return true;
		}
		return false;
	}
	
}
